//
//  WAccount.m
//  WeChat
//
//  Created by Yanting on 16/7/14.
//  Copyright © 2016年 Yanting. All rights reserved.
//

#import "WAccount.h"
#define UserKey @"user"
#define PwdKey @"pwd"
#define LoginKey @"login"
@implementation WAccount


+(instancetype)shareAccount{
    return [[self alloc]init];
}
#pragma mark 分配内存创建对象
+(instancetype)allocWithZone:(struct _NSZone *)zone{
    NSLog(@"%s",__func__);
    static WAccount *account;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        account = [super allocWithZone:zone];
        
        //从沙盒获取上次用户登录信息
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        account.user = [defaults objectForKey:UserKey];
        account.pwd = [defaults objectForKey:PwdKey];
        account.login = [defaults boolForKey:LoginKey];
        

    });
    return account;
}

-(void)saveToSandBox{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:self.user forKey:UserKey];
    [defaults setObject:self.pwd forKey:PwdKey];
    [defaults setBool:self.isLogin forKey:LoginKey];
    [defaults synchronize];
}
@end
